﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using BASE;

public partial class sualylich : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Utils.getStringSession("masv") == "")
        {
            Response.Redirect("/");

        }
        Session["menu"] = Constants.SUALYLICH;
        if (!IsPostBack)
        {
            
            binDanToc();
            dr_dt.Items.Insert(0, new ListItem("--Chọn dân tộc--","0"));
            entSinhVien entSV = new entSinhVien();
            busSinhVien busSV = new busSinhVien();
            entSV = busSV.getSinhVienByMaSV(Utils.getStringSession("masv"));
            txt_ten.Text = entSV.Ten;
            txt_ho.Text = entSV.Ho;
            txt_ngaysinh.Text = entSV.NgaySinh;
            txt_CMTND.Text = entSV.CMTND;
            txt_hokhau.Text = entSV.HoKhau;
            txt_noisinh.Text = entSV.NoiSinh;
            txt_htb.Text = entSV.HoTenBo;
            txt_nnb.Text = entSV.NNBo;
            txt_htm.Text = entSV.HoTenMe;
            txt_nnm.Text = entSV.NNMe;
            txt_namtg.Text = entSV.NamTN12;
            txt_sohieubang.Text = entSV.SoHieuBang12;
            txt_tongiao.Text = entSV.TonGiao;
            txt_noicap.Text = entSV.NoiCap;
            txt_ngaycap.Text = entSV.NgayCap;
            ListItem lstitem = new ListItem();
            lstitem = dr_dt.Items.FindByValue(entSV.DanToc.ToString());
            if (lstitem != null)
            {
                lstitem.Selected = true;
            }
            lstitem = new ListItem();
            lstitem = rd_phai.Items.FindByValue(entSV.GioiTinh.ToString());
            if (lstitem != null)
            {
                lstitem.Selected = true;
            }
            
        }
    }
    void binDanToc()
    {
        busDanToc busDT = new busDanToc();
        dr_dt.DataSource = busDT.getALL();
        dr_dt.DataTextField = "Ten";
        dr_dt.DataValueField = "DanTocId";
        dr_dt.DataBind();
    }
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        List<WebControl> lstweb = new List<WebControl>();
        lstweb.Add(txt_ten);
        lstweb.Add(txt_ngaysinh);
        lstweb.Add(dr_dt);
        lstweb.Add(txt_ngaycap);
        lstweb.Add(txt_namtg);
        string check = Utils.checkDataType(lstweb);
        if (check != "")
        {
            lb_me.Text = check;
            return;
        }
        lb_me.Text = "";
        entSinhVien entSV = new entSinhVien();
        busSinhVien busSV = new busSinhVien();
        entSV.MaSinhVien = Utils.getStringSession("masv");
        entSV.Ten = txt_ten.Text;
        entSV.Ho = txt_ho.Text;
        entSV.NgaySinh = txt_ngaysinh.Text;
        entSV.GioiTinh = int.Parse(rd_phai.SelectedValue);
        entSV.CMTND = txt_CMTND.Text;
        entSV.HoKhau = txt_hokhau.Text;
        entSV.NoiSinh = txt_noisinh.Text;
        entSV.HoTenBo = txt_htb.Text;
        entSV.NNBo = txt_nnb.Text;
        entSV.HoTenMe = txt_htm.Text;
        entSV.NNMe = txt_nnm.Text;
        entSV.NamTN12 = txt_namtg.Text;
        entSV.SoHieuBang12 = txt_sohieubang.Text;
        entSV.DanToc = int.Parse(dr_dt.SelectedValue);
        entSV.TonGiao = txt_tongiao.Text;
        entSV.NgayCap = txt_ngaycap.Text;
        entSV.NoiSinh = txt_noicap.Text;
        entSV.NoiCap = txt_noicap.Text;
        busSV.updatelylich(entSV);
        lb_me.Text = "Cập nhật thành công";
    }
}